package com.lpx.utils;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

import com.lpx.word.api.interfaces.IDocument;
import com.lpx.word.w2004.Document2004;
import com.lpx.word.w2004.elements.BreakLine;
import com.lpx.word.w2004.elements.Heading1;
import com.lpx.word.w2004.elements.Paragraph;

public class MyWord {
    public static void main(String[] args) {
        IDocument myDoc = new Document2004();
        myDoc.addEle(Heading1.with("昕").create());
        myDoc.addEle(BreakLine.times(2).create()); //two break lines
        myDoc.addEle(Paragraph.with("月亮代表我的心").create());
        //then get the XML representation of the MS Word document
        String myWord = myDoc.getContent();
        System.out.println(myWord);
    
        File fileObj = new File("D:\\Java2word_allInOne.doc");
                   //将生成的xml内容写入到文件中。
        PrintWriter writer = null;
        try {
            writer = new PrintWriter(fileObj);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        writer.println(myWord);
        writer.close();
    }
}